import { ChannelConfig } from "../../src/config/ChannelConfig";


export class WebVersionModel {

    public channel: number;
    public name: string;
    public strong_version: string //最低版本号，强更新版本号
    public no_update_version: string; //不热更版本号
    public version: string;

    constructor(channel: number, name: string, strong_version: string, no_update_version: string, version: string) {
        this.channel = channel;
        this.name = name;
        this.strong_version = strong_version;
        this.no_update_version = no_update_version;
        this.version = version;
    }

    //版本控制
    public static versionConfig: Map<number, WebVersionModel> = new Map<number, WebVersionModel>();

    // public static ios_download_url: string = "http://ibirdgame.cn:9604/202109245.apk"
    // public static android_download_url: string = "http://ibirdgame.cn:9604/202109245.apk"
    // public static ios_download_url: string = "https://iw.vdsc.cc/"
    // public static android_download_url: string = "https://iw.vdsc.cc/"


    // public static ios_download_url: string = "https://app.vdsc.cc/44sek5"
    // public static android_download_url: string = "https://app.vdsc.cc/44sek5"

    // http://xy2hc.fir.run/downpage/58ac547a9c454986
    // http://922tr.fir.run/downpage/c629fbdc1b5b4a4e

    // https://down.iememt.org/downpage/c629fbdc1b5b4a4e
    public static ios_download_url: string = "https://down.iememt.org/downpage/c629fbdc1b5b4a4e"
    public static android_download_url: string = "https://down.iememt.org/downpage/c629fbdc1b5b4a4e"
    // https://app.vdsc.cc/vcgbfn



    public static initConfig() {
        this.versionConfig.set(ChannelConfig.Channel_Type.Web, new WebVersionModel(ChannelConfig.Channel_Type.Web, "web", "1.0.0", "0", "1.0.0"))
        this.versionConfig.set(ChannelConfig.Channel_Type.Ios, new WebVersionModel(ChannelConfig.Channel_Type.Ios, "Ios", "1.0.0", "0", "1.0.999"))
        this.versionConfig.set(ChannelConfig.Channel_Type.android, new WebVersionModel(ChannelConfig.Channel_Type.android, "android", "1.0.0", "1", "1.0.999"))
    }

    private static compareVersion(a_version: string, b_version: string) {
        let a: Array<string> = a_version.split(".")
        let b: Array<string> = b_version.split(".")
        for (let i = 0; i < a.length; i++) {
            if (parseInt(a[i]) < parseInt(b[i])) {
                return true;
            }
        }
        return false;
    }

    public static getForceUpdate(channel: number, now_version: string) {
        let needUpdate: boolean = false;
        let model: WebVersionModel = this.versionConfig.get(channel)
        if (model) {
            if (channel == ChannelConfig.Channel_Type.Ios) {
                if (now_version == model.no_update_version) {//审核Ios时用
                    return needUpdate;
                }
                else {
                    if (this.compareVersion(now_version, model.strong_version)) {
                        needUpdate = true;
                    }
                }
            } else {
                if (this.compareVersion(now_version, model.strong_version)) {
                    needUpdate = true;
                }
            }
        }
        return needUpdate
    }

    public static getNeedUpate(channel: number, now_version: string) {
        let needUpdate: boolean = false;
        let model: WebVersionModel = this.versionConfig.get(channel)
        if (model) {
            if (channel == ChannelConfig.Channel_Type.Ios) {
                if (now_version == model.no_update_version) {//审核Ios时用
                    return needUpdate;
                }
                else {
                    if (this.compareVersion(now_version, model.version)) {
                        needUpdate = true;
                    }
                }
            } else {
                if (this.compareVersion(now_version, model.version)) {
                    needUpdate = true;
                }
            }
        }
        return needUpdate
    }


}